<?php
/**
 * 从开放的天气预报服务中获得数据
 *
**/
 
$c = new SoapClient( 'http://www.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl',
                 array( 'trace' => true, 'exceptions' => true ) );

//查看接口中的方法
//var_dump( $c->__getFunctions() );
//查看接口方法的使用
//var_dump( $c->__getTypes() );
//不需要参数的情况
$pr =$c->getRegionProvince();
//var_dump( $pr->getRegionProvinceResult->string );
 
//带有参数的情况
$scs = $c->getSupportCityString( array( 'theRegionCode' => '湖南' ) );
var_dump( $scs->getSupportCityStringResult->string );
 
//也可以这样做
$we = $c->__call('getWeather', array( array( 'theCityCode' => 1670 ) ) );
 
$arr = object_array($we);

var_dump($arr['getWeatherResult']['string']);


//PHP stdClass Object转array  
function object_array($array) {  
    if(is_object($array)) {  
        $array = (array)$array;  
     } if(is_array($array)) {  
         foreach($array as $key=>$value) {  
             $array[$key] = object_array($value);  
             }  
     }  
     return $array;  
}
?>